<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@include file="../../mytags.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title>巡检设备</title>
    <t:base type="jquery"></t:base>
    <script type="text/javascript" src="webpage/com/wx/added_product/procurement/shoppingCar.js"></script>
    <script type="text/javascript" charset="utf-8">
        mui.init();
    </script>
</head>
<body>
<script type="text/jTemplate" id="equipTemplate">
    {#foreach $T as item}
    {#if $T.item.isInRepair != "2"}
    <li data-inspectionType="{$T.item.inspectionType}">
        <div class="mui-input-row mui-checkbox mui-left li_f mui-clearfix">
            <input name="checkbox" value="{$T.item.id}" type="checkbox" class="checkbox1"
                   data-sn="{$T.item.sn}"
                   data-type="{$T.item.inspectionType}"
            />
            <div class="inr">
                <h3>设备序列号-{$T.item.sn}
                    <span class="zz" <%--style="background: #e70012;"--%>>在保</span>
                </h3>
                <div class="inrr">
                    <h4><span>设备型号</span>{$T.item.type}</h4>
                    <h4><span>厅号</span>{$T.item.room}</h4>
                </div>
            </div>
        </div>
        {#if $T.item.inspectionType == "0"}
        <div class="tix mui-clearfix" style="color: #0086cc;background: #e5f3fa; border: 1px solid #66b6e0;">
            <img src="${webRoot}images/jg2.png">${year}年度无巡检计划
        </div>
        {#elseif $T.item.inspectionType == "2"}
        <div class="tix mui-clearfix">
            <img src="${webRoot}images/jg.png">${year}年度已计划巡检
        </div>
        {#elseif $T.item.inspectionType == "1"}
        <div class="tix mui-clearfix" style="color: #0eb972;background: #e6f8f1; border: 1px solid #6ed5aa;">
            <img src="${webRoot}images/jg1.png">${year}年度已巡检
        </div>
        {/#if}
    </li>
    {/#if}
    {/#for}
</script>
<div class="fp_t">共计<span id="sumEquip">${equipCount}</span>台设备(${serviceCount}台在保)</div>
<div class="mui-card pps"  style="margin:0px;">
    <span style="width:100%; color:red;font-size:12px;text-align:center;">
        温馨提示：尊敬的客户，出保设备巡检和计划外巡检需支付额外费用。
    </span>
</div>
<div class="mui-card" style="margin: 0;margin-bottom: 60px; box-shadow:none; background: none;">

    <ul class="mui-table-view hn kk" id="equipListUl">

    </ul>

</div>
<div class="mui-checkbox car-footer" style="position:fixed">
    <input name="checkbox" value="Item 1" type="checkbox" class="checkall">
    <span class="qx" style="float: left;padding-left: 34px;">全选</span>
    <div class="btn" onclick="goSign()">巡检预约</div>
</div>
<%--<div class="mui-input-row mui-checkbox mui-left  quanx">
    <input name="checkbox" value="" type="checkbox" class="checkall">
    <h3>全选<a onclick="goSign()">巡检预约</a></h3>
</div>--%>
<script type="text/javascript">
    var ids = "${ids}";
    function initUserEquip() {
        if (ids != "") {
            $.post("cbsPartInfoController.do?getEquipmentIdById", {id: ids}, function (data) {
                data = $.parseJSON(data);
                if (!$.isEmptyObject(data)) {
                    $("#equipListUl").setTemplate($("#equipTemplate").html()).processTemplate(data);
                    $(":checkbox").each(function () {
                        if ($(this).attr("data-type") == "2") {
                            $(this).attr("disabled", "disabled");
                        }
                    })
                    $("#equipListUl li").click(function(){
                        var o = $(this);
                        if(o.attr("data-inspectionType") == "2"){
                            mui.toast("设备已有巡检计划，本年度不能再次预约");
                        }
                    })
                    _Car.handleCheckAll();
                }
            })

        }
    }

    /**
     * 跳转到填写信息页面
     */
    function goSign() {
        var checkIds = new Array();
        var types = new Array();
        var sn = new Array();
        $(":checked").not(".checkall").each(function () {
            if ($(this).val() != '') {
                checkIds.push($(this).val());
                sn.push($(this).attr("data-sn"));
                types.push($(this).attr("data-type"));
            }
        })
        if (checkIds.length == 0) {
//            mui.toast("请选择巡检设备");
            mui.alert("未选择巡检设备或选择的设备中包含本年度已计划巡检设备");
            return;
        }
        localStorage.setItem(_Car.STORAGEKEY.xjyyEquipSn, sn.join(","));
        if (checkIds.length > 0) {
            mui.confirm("请确认是否提交巡检申请", "预约提示", '', function (btn) {
                if (btn.index == 1) {
                    mui.openWindow({
                        createNew: true,
                        url: 'inspectionWx.do?goSign&ids=' + checkIds.join(",") + "&types=" + types.join(",")
                    })
                }
            })

        }
    }

    $(function () {
        initUserEquip();
        $(".checkall").attr("checked", false);
        localStorage.removeItem(_Car.STORAGEKEY.xjyyEquipSn);
        $(".checkall").click(function () {
            $(".checkbox1").each(function () {
                console.log($(this).attr("data-type"));
                if ($(this).attr("data-type") != "2") {
                    $(this).attr("checked", $(".checkall").is(":checked"));
                }
            })
        })
    })
</script>
</body>
</html>